package com.liushao.result;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: untitled1
 * @ClassName Result
 * @description:
 * @author: 陈修华
 * @create: 2025−01-03 10:34
 * @Version 1.0
 **/
//@Data
public class Result {

    private Integer code;//code码
    private String message;//信息
    //数据
    private Map<String,Object> data  = new HashMap<>();

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }



    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    private Result() {
    }

    public static  Result ok(){
        Result r = new Result();
        r.setCode(ResponseEnum.SUCCESS.getCode());
        r.setMessage(ResponseEnum.SUCCESS.getMessage());
        return r;
    }

    public static  Result error(){
        Result r = new Result();
        r.setCode(ResponseEnum.ERROR.getCode());
        r.setMessage(ResponseEnum.ERROR.getMessage());
        return r;
    }

    //设置特定的结果
    public static  Result setResult(ResponseEnum responseEnum){
        Result r = new Result();
        r.setCode(responseEnum.getCode());
        r.setMessage(responseEnum.getMessage());
        return r;
    }

    public Result message(String message){
          this.setMessage(message);
          return this;
    }

    public Result code(Integer code){
        this.setCode(code);
        return this;
    }


    public Result data(String key,Object value){
        this.data.put(key,value);
        return this;
    }

    public Result data(Map<String,Object> map){
        this.setData(map);
        return this;
    }


    //public static void main(String[] args) {
    //    List  list  = new ArrayList<>();
    //    list.add("1");
    //    list.add("2");
    //    list.forEach(System.out::println);
    //    list.forEach(item-> System.out.println(item));
    //    Object l = list;
    //    System.out.println(l);
    //}

}
